import 'package:base/base/theme.dart';
import 'package:base/base_lib.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:login/router.dart';
import 'package:more/res/images.dart';
import 'package:more/res/style.dart';

import '../res/lang.dart';
import 'more_logic.dart';

class MorePage extends StatelessWidget {
  final logic = Get.put<MoreLogic>(MoreLogic());

  MorePage({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: PreferredSize(
          preferredSize: Size.fromHeight(80.h),
          child: AppBar(
              bottom: ToolBar.custom(GestureDetector(
            child: _toolBar,
            onTap: () => LoginRouter.goLoginSignup(),
          )))),
      body: _body(context),
    );
  }

  Widget _body(BuildContext context) {
    return CustomScrollView(
      physics: const BouncingScrollPhysics(),
      slivers: [
        _headerBox,
        SliverToBoxAdapter(
            child: Column(
          mainAxisAlignment: MainAxisAlignment.start,
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            20.height,
            Row(children: [
              MoreImageRes.ic_more_account.menuIcon,
              3.width,
              MoreStrRes.learn_more.menuText,
            ]).setMenuItem(onTap: () {}),
            Row(
              children: [
                MoreImageRes.ic_more_gift_card.menuIcon,
                3.width,
                MoreStrRes.gift_card.menuText,
              ],
            ).setMenuItem(onTap: () {}),
            Row(
              children: [
                MoreImageRes.ic_more_keys.menuIcon,
                3.width,
                MoreStrRes.how_turo_works.menuText,
              ],
            ).setMenuItem(onTap: () {}),
            Row(
              children: [
                MoreImageRes.ic_more_suport.menuIcon,
                3.width,
                MoreStrRes.contact_support.menuText,
              ],
            ).setMenuItem(onTap: () {}),
            Row(
              children: [
                MoreImageRes.ic_more_document.menuIcon,
                3.width,
                MoreStrRes.legal.menuText,
              ],
            ).setMenuItem(onTap: () {}),
            10.height,
            1.0.line(),
            Row(children: [Text(MoreStrRes.logout)]).setMenuItem(onTap: () {
              logic.showLogout(context);
            }),
            5.height,
            "${MoreStrRes.version} ${logic.version}"
                .menuText
                .paddingOnly(left: 12.w),
            10.height,
          ],
        ))
      ],
    );
  }

  Widget get _toolBar {
    return Row(
      crossAxisAlignment: CrossAxisAlignment.start,
      children: [
        logic.userAvatar.isNotEmpty
            ? logic.userAvatar.value.network()
            : MoreImageRes.icon_user_avatar.assetRealImage(),
        10.width,
        Column(
          mainAxisAlignment: MainAxisAlignment.start,
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            Text(logic.userName.value, style: KTheme.normalTextStyle14),
            Text(MoreStrRes.view_and_edit_profile,
                style: KTheme.normalTextStyle14),
          ],
        )
      ],
    );
  }

  Widget get _headerBox {
    return SliverToBoxAdapter(
        child: Card(
      clipBehavior: Clip.antiAlias,
      shape: RoundedRectangleBorder(
        borderRadius: BorderRadius.all(Radius.circular(14.r)),
      ),
      child: SizedBox(
        height: 200.h,
        child: Row(
          children: [
            Expanded(
                flex: 2,
                child: Column(
                    crossAxisAlignment: CrossAxisAlignment.start,
                    mainAxisAlignment: MainAxisAlignment.start,
                    children: [
                      MoreStrRes.become_a_host.titleText,
                      MoreStrRes.more_host_warn.titleText,
                      DebounceButton(
                        style: ButtonStyle(
                          minimumSize:
                              MaterialStateProperty.all(Size(100.w, 40.h)),
                          visualDensity: VisualDensity.compact,
                          padding: MaterialStateProperty.all(EdgeInsets.zero),
                          backgroundColor:
                              MaterialStateProperty.all(KColors.c_1B72EC),
                          shape: MaterialStateProperty.all(
                              RoundedRectangleBorder(
                                  borderRadius:
                                      BorderRadius.all(Radius.circular(10.r)))),
                        ),
                        onPressed: () {},
                        child: MoreStrRes.learn_more.text12sp,
                      ),
                    ]).paddingOnly(left: 12.w, top: 14.h, right: 14.w)),
            Container(
              color: KColors.c_1B72EC,
              width: 80.w,
              height: 200.h,
              child: logic.userAvatar.isNotEmpty
                  ? logic.userAvatar.value.network()
                  : MoreImageRes.icon_user_avatar.assetRealImage(),
            )
          ],
        ),
      ),
    ).paddingOnly(left: 12.w, top: 12.w, right: 12.w));
  }
}
